package com.guxingke.typecho4j.widget.provider.content;

import java.util.List;

import com.guxingke.typecho4j.Typecho4jException;
import com.guxingke.typecho4j.jfinal.model.Content;
import com.guxingke.typecho4j.util.PageBean;
import com.guxingke.typecho4j.util.PageUtil;
import com.guxingke.typecho4j.widget.WidgetProvider;
import com.guxingke.typecho4j.widget.provider.ContentBaseWidget;
import com.jfinal.core.Controller;

public class PostsManageWidget extends ContentBaseWidget implements
		WidgetProvider {

	@Override
	public void excute(Controller controller) throws Typecho4jException {
		Integer page = controller.getParaToInt("page");
		Integer pageSize = constants.getPageSize();
		if (page == null) {
			page = 1;
		}

		List<Content> posts = getPosts(new PageBean(page, pageSize));
		controller.setAttr("posts", posts);

		// TODO
		String pageNav = PageUtil.getPagation(constants.getSiteUrl()
				+ "/admin/manage-posts", 3, page, pageSize);
		controller.setAttr("pageNav", pageNav);
	}

	@Override
	public void refresh() {
		// TODO Auto-generated method stub

	}

}
